package com.qf.test;

import com.alibaba.fastjson.JSON;
import com.qf.pojo.User;
import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.Date;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.test
 * @Description:
 * @Date 2022/6/29 11:26
 */
public class Demo3 {
    @Test
    public void name() {
        Jedis jedis = new Jedis("192.168.200.129", 6379);
        String stringKey="stringUser";
        User user = new User(2,"代理",new Date());
        //2.2 使用fastJSON将value转化为json字符串
        String s = JSON.toJSONString(user);
        jedis.set(stringKey, s);
        jedis.close();
    }

    @Test
    public void get() {
        Jedis jedis = new Jedis("192.168.200.129", 6379);
        String key="stringUser";
        String s = jedis.get(key);
        User user = JSON.parseObject(s, User.class);
        System.out.println(user);
        jedis.close();
    }
}
